#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <linux/input.h> //交叉编译器中的头文件，不是内核的

struct key_report{
	int code;
	int value;
};

int main(void)
{
	int fd;
	struct key_report event;
	fd = open("/dev/key_drv",O_RDWR);
	if(fd < 0)
	{
		perror("open");
		exit(1);
	}
	while(1)
	{
		read(fd, &event, sizeof(event));
		switch(event.code)
		{
			case KEY_A:
			{
				if(event.value == 0)
					printf("KEY_A----->pressed\n");
				else
					printf("KEY_A----->released\n");
			}
				break;
			case KEY_B:
			{
				if(event.value == 0)
					printf("KEY_B----->pressed\n");
				else
					printf("KEY_B----->released\n");
			}
				break;
			case KEY_C:
			{
				if(event.value == 0)
					printf("KEY_C----->pressed\n");
				else
					printf("KEY_C----->released\n");
			}
				break;
			default:
				break;
		}
	}
	close(fd);
	return 0;
}
